package cn.edu.ncut.cs.springboot.petmanagementsystem.controller;

import cn.edu.ncut.cs.springboot.petmanagementsystem.common.PageResult;
import cn.edu.ncut.cs.springboot.petmanagementsystem.common.Result;
import cn.edu.ncut.cs.springboot.petmanagementsystem.pojo.PetBreed;
import cn.edu.ncut.cs.springboot.petmanagementsystem.service.PetBreedService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 宠物品种控制器
 */
@Tag(name = "宠物品种模块")
@RestController
@RequestMapping("/breed")
@RequiredArgsConstructor
public class BreedController {
    
    private final PetBreedService petBreedService;
    
    /**
     * 获取宠物品种列表
     */
    @Operation(summary = "获取宠物品种列表")
    @GetMapping("/list")
    public PageResult<PetBreed> getBreedList(
            @Parameter(description = "当前页") @RequestParam(defaultValue = "1") int page,
            @Parameter(description = "每页大小") @RequestParam(defaultValue = "10") int size,
            @Parameter(description = "宠物类型") @RequestParam(required = false) String petType) {
        
        IPage<PetBreed> pageResult = petBreedService.getBreedList(page, size, petType);
        return PageResult.success(pageResult);
    }
    
    /**
     * 获取品种详情
     */
    @Operation(summary = "获取品种详情")
    @GetMapping("/{id}")
    public Result<PetBreed> getBreedDetail(
            @Parameter(description = "品种ID") @PathVariable Long id) {
        
        PetBreed breed = petBreedService.getBreedDetail(id);
        if (breed == null) {
            return Result.error(404, "品种不存在");
        }
        
        return Result.success(breed);
    }
}
